package cn.com.dcsgo.service.impl;

import cn.com.dcsgo.mapper.ActivityRuleMapper;
import cn.com.dcsgo.model.activity.ActivityRule;
import cn.com.dcsgo.model.activity.ActivitySku;
import cn.com.dcsgo.service.ActivityRuleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ActivityRuleServiceImpl
 *
 * @author Dcsgo
 * @since 11/5/2025 下午 3:32
 */
@Service
public class ActivityRuleServiceImpl extends ServiceImpl<ActivityRuleMapper, ActivityRule> implements ActivityRuleService {
    @Override
    public List<ActivityRule> getList(List<ActivitySku> activitySkuList) {
        if (CollectionUtils.isEmpty(activitySkuList)) {
            return new ArrayList<>(0);
        }
        return baseMapper.selectList(new LambdaQueryWrapper<ActivityRule>()
                .in(
                        ActivityRule::getActivityId,
                        activitySkuList.stream().map(ActivitySku::getActivityId).collect(Collectors.toSet()))
                .orderByDesc(ActivityRule::getConditionAmount, ActivityRule::getConditionNum)
        );
    }
}
